//
//  BaseViewController.m
//  Bus_iPhone
//
//  Created by antunnel on 12-7-2.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

@synthesize autoDeselectTableView=_autoDeselectTableView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        _autoDeselectTableView=YES;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    if ([self isIos5Later]) {
        UIImage *img=[UIImage imageNamed:@"header_bg.png"];
        [self.navigationController.navigationBar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
    }
    
    UIImage *bgImg=[UIImage imageNamed:@"chat_bg.png"];
    self.view.backgroundColor=[UIColor colorWithPatternImage:bgImg];
    
	// Do any additional setup after loading the view.
}



- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

-(void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    
    if (self.autoDeselectTableView) {
        for (UIView *view in self.view.subviews) {
            if ([view isKindOfClass:[UITableView class]]) {
                UITableView *tempTableView=(UITableView *)view;
                NSIndexPath *indexPath=[tempTableView indexPathForSelectedRow];
                if (indexPath) {
                    [tempTableView deselectRowAtIndexPath:indexPath animated:YES];
                }
            }
        }
    }
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end


@implementation UINavigationBar (Custom)

-(void)drawRect:(CGRect)rect{

    UIImage *img=[UIImage imageNamed:@"header_bg.png"];
    [img drawInRect:rect];
}

@end